import 'package:flutter/material.dart';
import 'data_source/data.dart';
import 'ui_demo_listView_detail.dart';
import '../wonders/framework.dart';

class ListViewDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _ListViewState();
  }
}

class _ListViewState extends State<ListViewDemo> with WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }
  @override
  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
//    return ListView.builder(
//        itemCount: imagesList.length, itemBuilder: _listItemBuilder);
    return ListLayout(itemCount: imagesList2.length, builder: _listItemBuilder);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    //页面生命周期状态日志
    LogUtils.instance.logState(state, this.runtimeType);
  }
  Widget _listItemBuilder(BuildContext context, int index) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.fromLTRB(5, 10, 5, 0),
      padding: EdgeInsets.all(10.0),
      child: Stack(
        children: <Widget>[
          Column(
            children: <Widget>[
              //Image.asset("assets/images/4.jpg"),
              AspectRatio(
                  aspectRatio: 16 / 9,
                  child: Image.network(
                    imagesList2[index].url,
                    fit: BoxFit.cover,
                  )),
              SizedBox(
                height: 10.0,
              ),
              Text(
                imagesList2[index].name,
                style: TextStyle(fontSize: 14.0),
              ),
              Text(
                imagesList2[index].desc,
                style: TextStyle(color: Colors.black54),
              ),
            ],
          ),
          Positioned.fill(
            child: Material(
              color: Colors.transparent,
              child: InkWell(
                splashColor: Colors.white.withOpacity(0.3),
                highlightColor: Colors.white.withOpacity(0.1),
                onTap: () {
                  debugPrint("InkWell");
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) {
                    return ListViewDetailDemo(imagesList2[index]);
                  }));
                },
              ),
            ),
          )
        ],
      ),
    );
  }
}
